package com.android.nodejs.livejs.activities;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.android.nodejs.livejs.R;

public class AddFriendActivity extends Activity {
	
	private EditText edtSearch;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_friend);
		
		edtSearch = (EditText) findViewById(R.id.edtSearch);
		edtSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {

            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (edtSearch.getText().toString().trim().equals("")) {
                    Toast.makeText(getApplicationContext(), "Please enter information to search", Toast.LENGTH_SHORT).show();
                    return false;
                }
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    //placeAdapter.clear();
                    ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getCurrentFocus()
                            .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                    //process search
                    return true;
                }
                return false;
            }
        });
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_add_friend, menu);
		return true;
	}

	public void onClickBack(View v) {
		setResult(RESULT_CANCELED);
		finish();
	}

	public void onClickSearch(View v) {
	    String strSearch = edtSearch.getText().toString().trim();
        if("".equals(strSearch) == true) {
            Toast.makeText(getApplicationContext(), "Nothing for search! You must enter data!", Toast.LENGTH_LONG).show();
        } else {
            //TODO tim kiem add friend
            Toast.makeText(getApplicationContext(), strSearch, Toast.LENGTH_LONG).show();
        }
	}
}
